<?php
/**
* Databse table prefix change script
* by Jitu
* 
* @param string $old_prefix 
* @param string $new_prefix
* 
* @return int|false the number of table altered or false if not 
*/


$server="localhost";
$user="root";
$password="";
$database="temp_chikitsha";
$old_prefix="byp_";
$new_prefix="chi_";

$conn = mysql_connect($server, $user, $password);

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
  
if (!mysql_select_db($database)) {
    echo "Unable to select $database: " . mysql_error();
    exit;
}




    $result = mysql_query('show tables');
    
    $count=0;
    
    while($row = mysql_fetch_assoc($result)){
        $key='Tables_in_'.$database;
        if(strstr($row[$key],$old_prefix)){
            $alt_sql="alter table {$row[$key]} rename {$new_prefix}".str_replace($old_prefix,'',$row[$key])."";
            if(mysql_query($alt_sql))
                $count++;
        }
    }
    
    if($count) echo 'success';
    else echo 'failed!'
    

?>